var app =new Vue({
    el:"#container",
    data:{
        user:{},
        xData:[],
        yData:[],
        jobNumber:"",
        startTime:"",
        endTime:""
    },
    mounted(){
        this.userInfo();
        this.showEcharts();
    },
    methods:{
        userInfo(){
            axios({
                url:"yly-api/admin/queryEmpAccountByToken",
                method:"get",
                headers:{"token":localStorage.token,"url":window.location.pathname}
            }).then(function (res) {
                console.log(res);
                app.user=res.data;
            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("权限不足，无法访问!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },
        showEcharts(jobNumber,startTime,endTime){
            let data=new URLSearchParams();
            data.append("jobNumber",jobNumber);
            data.append("startTime",startTime);
            data.append("endTime",endTime);
            axios({
                url:"yly-api/admin/queryNumberOfNursing",
                method:"post",
                headers:{"token":localStorage.token,"url":window.location.pathname},
                data:data
            }).then(function (res) {
                console.log(res.data);
                let echarts=res.data.data;

                app.xData=[];
                app.yData=[];
                $.each(echarts,function (index,ex) {
                    app.xData[index]=ex.createdate;
                });
                $.each(echarts,function (index,ex) {
                    app.yData[index]=ex.number;
                });
                console.log(app.xData);
                console.log(app.yData);

                app.setEcharts();
            }).catch(function (error) {
                // console.log(error.response.status);
                // if (error.response.status==401){
                //     alert("权限不足，无法访问!");
                //     location.href="login.html";
                // }else if (error.response.status==403){
                //     alert("用户已过期，请重新登录！");
                //     localStorage.token=null;
                //     location.href="login.html";
                // }
            });
        },
        setEcharts(){

            // document.getElementById('main').innerHTML = "";
            document.getElementById("main").removeAttribute("_echarts_instance_");
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));


            // 指定图表的配置项和数据
            var option = {
                xAxis: {
                    type: 'category',
                    data: app.xData
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    data: app.yData,
                    type: 'line',
                    smooth: true
                }]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
    }
});
